package edu.ccut.saturn.studio.logic.figure;

import org.eclipse.draw2d.AbstractBorder;
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Insets;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.PointList;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.graphics.Color;

public class PageFigure extends Figure {

	public static Color backgroundColor = new Color(null, 255, 255, 206);

	private CompartmentFigure imageFigure = new CompartmentFigure();

	private CompartmentFigure letterFigure = new CompartmentFigure();

	public PageFigure() {
		ToolbarLayout layout = new ToolbarLayout();
		layout.setStretchMinorAxis(true);
		layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
		layout.setSpacing(2);
		setLayoutManager(layout);
		add(imageFigure);
		add(letterFigure);
		// setBorder(new AttributesFigureBorder());
	}
	public  CompartmentFigure getImageFigure() {
		return imageFigure;
	}

	public void setImageFigure(CompartmentFigure imageFigure) {
		this.imageFigure = imageFigure;
	}

	public CompartmentFigure getLetterFigure() {
		return letterFigure;
	}

	public void setLetterFigure(CompartmentFigure letterFigure) {
		this.letterFigure = letterFigure;
	}

	public Rectangle getTextBounds() {
		return this.letterFigure.getBounds();
	}

	class AttributesFigureBorder extends AbstractBorder {

		public Insets getInsets(IFigure figure) {
			return new Insets(1, 0, 0, 0);
		}

		public void paint(IFigure figure, Graphics graphics, Insets insets) {
			PointList points = new PointList();

			int width = figure.getBounds().width;
			int height = figure.getBounds().height;
			Point point = figure.getBounds().getLocation();
			Point point2 = new Point(point.x + width - 1, point.y);
			Point point3 = new Point(point.x + width - 1, point.y + height - 1);
			Point point4 = new Point(point.x, point.y + height - 1);

			points.addPoint(point);
			points.addPoint(point2);
			points.addPoint(point3);
			points.addPoint(point4);

			graphics.drawPolygon(points);

		}
	}
}
